package dao;

import users.User;
import util.JdbcUtil;


import java.sql.*;

public class UserDao {
    public static User login(String username, String password){
        User u = null;
        Connection cn = null;
        Statement st = null;
        ResultSet rs = null;

        try {
            cn = JdbcUtil.getcon();
            String sql = "select * from user where username='"+username+"' and password='"+password+"'";
            st = cn.createStatement();
            rs = st.executeQuery(sql);
            if(rs.next()){
                u = new User();
                u.setUsername(rs.getString("username"));
                u.setPassword(rs.getString("password"));
            }
            else{
                u = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally{
            JdbcUtil.close(rs,st,cn);
        }
        return u;
    }

}
